﻿
#ifndef __NGX_CONF_H__
#define __NGX_CONF_H__

#include <unordered_map>
#include <pthread.h>
#include "ngx_global.h"  //一些全局/通用定义

typedef  std::unordered_map<std::string, std::string> config_kv_t;
typedef std::unordered_map<std::string, config_kv_t> config_t;
//类名可以遵照一定的命名规则规范，比如第一个字母是C，后续的单词首字母大写
class CConfig
{
private:
	CConfig();
public:
	~CConfig();
private:
	static CConfig *m_instance;
    static pthread_once_t once;
    static void create_instance()
    {
        m_instance = new CConfig();
    }
public:	
	static CConfig* GetInstance() 
	{	
		if(m_instance == NULL)
		{
            pthread_once(&once, create_instance);
		}
		return m_instance;
	}	
	class CGarhuishou  //类中套类，用于释放对象
	{
	public:				
		~CGarhuishou()
		{
			if (CConfig::m_instance)
			{						
				delete CConfig::m_instance;
				CConfig::m_instance = NULL;				
			}
		}
	};
public:
    bool Load(const char *pconfName); //装载配置文件
	const char *GetString(const char *p_itemname, const char* sectionname="default");
	int  GetIntDefault(const char *p_itemname,const int def, const char* secctionname="default");

public:
    // 键和值的关系，使用map更为合适
   config_t configs;
};

#endif
